<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">书名</label>
                            <div class="layui-input-inline">
                                <input class="layui-input" name="name" id="name" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">作者</label>
                            <div class="layui-input-inline">
                                <input class="layui-input" name="author" id="author" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">出版社</label>
                            <div class="layui-input-inline">
                                <input class="layui-input" name="publishingHouse" id="publishingHouse" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="button" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn" id="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="detail">图书详情</a>
            <a class="layui-btn layui-btn-warm layui-btn-xs data-count-edit" lay-event="update">评论修改</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除评论</a>
        </script>

    </div>
</div>
<script>
    layui.use(['form', 'table','miniPage','element'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            miniPage = layui.miniPage;
        form.render();
        table.render({
            elem: '#currentTableId',
            url: '/borrowerCommentInfo',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [
                [
                    {field: 'id', title: '评论编号', sort: true},
                    {field: 'bookName', title: '书名', sort: true},
                    {field: 'author', title: '作者', sort: true},
                    {field: 'publishingHouse',title: '出版社', sort: true},
                    {field: 'score',title: '评分', sort: true},
                    {field: 'content',minWidth: 400, title: '评论', sort: true},
                    {title: '操作', minWidth: 250, toolbar: '#currentTableBar', align: "center"}
                ]
            ],
            limit: 15,
            page: true,
            skin: 'line'
        });

        layui.$('#data-search-btn').on('click',function () {
            //console.log(data.field)
            var author = document.getElementById('author').value,
                name = document.getElementById('name').value,
                publishingHouse = document.getElementById('publishingHouse').value;
            console.log(author)
            console.log(name)
            console.log(publishingHouse)
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    'author': author,
                    'bookName': name,
                    'publishingHouse' : publishingHouse
                }
            });

            return false;
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'delete') {
                layer.confirm('真的要删除评论么', function (index) {
                    $.ajax({
                        url: '/deleteComment',
                        type:'POST',
                        data:{
                            id:data.id,
                            bookName:data.bookName,
                            score:data.score
                        },
                        success:function (res){
                            if(res.code==200){
                                layer.close(index);
                                layer.msg("删除成功!");
                                parent.window.location.reload();
                            }else {
                                layer.msg(layer.msg(res.msg));
                            }
                        }

                    })
                });
            } else if (obj.event === 'detail') {
                var content = miniPage.getHrefContent('/borrowerBooksDetail?name='+data.bookName);
                var index = layer.open({
                    title: data.bookName,
                    type: 1,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['85%','75%'],
                    content: content,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if(obj.event === 'update'){
                var content = miniPage.getHrefContent('/borrowerCommentUpdate?id='+data.id);
                var index = layer.open({
                    title: '评论修改',
                    type: 1,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['85%','75%'],
                    content: content,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            }
            return false;
        });

    });
</script>
</body>
</html>

